package com.game.sdk.util;

import java.util.Iterator;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.game.sdk.YTAppService;

/***
 * @author ling(混淆代码的时候需要去抹去注释)
 * @date 2016-6-5
 * */
public class DataSafeUtil {
	public static int code = 0;// safe use

	public static int defultCode = 0;

	public static final int SEED = 10000;

	/**
	 * @return void
	 * 
	 * */
	public static void ititCode(int customCode) {
		if (customCode <= 0) {
			return;
		}
		code = customCode;
	}

	public static void radomCode() {
		Random random = new Random(SEED);
		code = random.nextInt();
	}

	/***
	 * @param function
	 *            接口名
	 * @param date
	 *            日期格式：date："2016-6-5"
	 * @param cliengkey
	 *            每个供应商的一个标识
	 * */
	public static String getApiToken(String function, long date,
			String clientkey) {
		return Md5Util.md5(function
				+ DateUtil.newInstance().getCurrentDateFormatDefult(date)
				+ DataSafeUtil.code + clientkey);
	}

	/***
	 * @param paramString
	 *            参数json字符串
	 * @param ApiToken
	 *            这个可以调用函数获取
	 * */
	public static String getIdentifyKey(String paramString, String clientKey) {

		return Md5Util.md5(Md5Util.md5(paramString) + clientKey);
	}

	/**
	 * return clientId
	 * */
	public static String getClientId() {
		return YTAppService.clientIdEntifier;
	}

	/**
	 * reuturn clientkey
	 * */
	public static String getClientKey() {
		return YTAppService.clientKey;
	}

}
